﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Reflection;
using Messaging2;
using u = FinPlusUtility.Utility;

namespace FinPlusRateServer
{
    //note no logging just stub/junk project to generate live feeds 
    class Program
    {
        private static u.Config _config;
        private static u.Env _env = u.Env.unknown; //gets from config

        static void Main(string[] args)
        {
            try
            {
                _config = u.ConfigXml(u.GetConfigPath(Assembly.GetExecutingAssembly()), out _env);

                var conn = new Transport(_config["messagingsettings"]["address"], int.Parse(_config["messagingsettings"]["port"]));

                var waitMilliseconds = int.Parse(_config["throttlesettings"]["waitmilliseconds"]);

                Console.WriteLine("Publishing live.");

                Generate g = new Generate(conn, _config, waitMilliseconds);

                Thread threadLive = new Thread(g.PublishLive);
                threadLive.Start();

                Console.WriteLine("Press <Enter> to publish close.");
                Console.ReadLine();

                Thread threadClose = new Thread(g.PublishClose);
                threadClose.Start();
               
                Console.WriteLine("Press <Enter> to stop.");
                Console.ReadLine();

                threadLive.Abort();
                threadClose.Abort();
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.ReadLine();
            }
        }
    }
   
}
